package com.LeetCode.List;

import org.junit.Test;

/**
 * 反转链表
 */
public class ReverseList {

    public ListNode reverseList(ListNode head) {
        ListNode pNode = head;
        ListNode prev = null;
        while(pNode!=null){
            ListNode next = pNode.next;
            pNode.next = prev;
            prev = pNode;
            pNode = next;
        }
        return prev;
    }

    @Test
    public void test(){
        ListNode head = new ListNode(1);
        ListNode pNode = head;
        for(int i = 2; i<=10; i++){
            pNode.next = new ListNode(i);
            pNode = pNode.next;
        }
        ListNode.printList(head);
        ListNode.printList(reverseList(head));
    }

}
